//
//  XRecommendedMoreViewController.m
//  Bees
//
//  Created by Xiaohan on 2018/12/21.
//  Copyright © 2018 xiaohan. All rights reserved.
//

#import "XRecommendedMoreViewController.h"
#import "XHomeItemCell.h"
#import "FoundModel.h"
#import "FoundServer.h"
#import "ScatterDappManager.h"
@interface XRecommendedMoreViewController ()
@property (nonatomic,strong) FoundServer *server;

@end

@implementation XRecommendedMoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self.tableView.mj_header beginRefreshing];
}
- (void)loadMore:(BOOL)isMore{
    [self.server getCategroyListIsMore:isMore completion:^(BOOL success,BOOL isHaveNextPage, NSString * _Nonnull msg) {
        [self endHeaderFooterRefreshingIsHaveNextPage:isHaveNextPage];
        if (success) {
            [self.tableView reloadData];
        }else{
            [self.view makeToast:msg];
        }
    }];
}
- (void)setupUI{
    self.tableView.rowHeight = AdaptedWidth(83);
    self.title = self.category.name;
    self.tableView.tableFooterView = [UIView new];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.server.categroyList.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XHomeItemCell *cell = [XHomeItemCell cellForTableView:tableView];
    FoundRecommendModel*model = [self.server.categroyList objectOrNilAtIndex:indexPath.row];
    [cell.imageV sd_setImageWithURL:String_To_URL(model.logo)];
    cell.titleLab.text = model.name;
    cell.subLab.text = model.introduction;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [ScatterDappManager manager:self
                        forDapp:[self.server.categroyList objectOrNilAtIndex:indexPath.row]];
}
#pragma mark - getter
- (FoundServer*)server{
    if (!_server) {
        _server = [FoundServer new];
        _server.categroyId = self.category.modelId;
    }
    return _server;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
